/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ConsultaExperta.java
 *
 * Created on 1/01/2005, 01:33:27 AM
 */
package zonasoft.Vistas.Negocio;

import com.mysql.jdbc.Connection;
import java.awt.Dimension;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
import zonasoft.Conceptos.Especiales.Barrio;
import zonasoft.Conceptos.Especiales.Departamentos;
import zonasoft.Conceptos.Especiales.Localidad;
import zonasoft.Conceptos.Especiales.Municipios;
import zonasoft.Conceptos.Especiales.UnidadComunera;
import zonasoft.Conceptos.Lider;
import zonasoft.Conceptos.Puesto;
import zonasoft.Conceptos.Zona;
import zonasoft.Conceptos.Zonificados;
import zonasoft.Manejadores.ManejadorBaseDatos;
import zonasoft.Manejadores.ManejadorDepartamentos;
import zonasoft.Manejadores.ManejadorLugar;
import zonasoft.Manejadores.ManejadorMunicipios;
import zonasoft.Manejadores.ManejadorPuesto;
import zonasoft.Manejadores.ManejadorQuerys;
import zonasoft.Manejadores.ManejadorZona;

/**
 *
 * @author Usuario
 */
public class ConsultaExperta extends javax.swing.JDialog {

    HashMap<String, Integer> departamentos;
    HashMap<String, Integer> municipios;
    HashMap<String, Integer> zonas;
    HashMap<String, Integer> puestos;
    HashMap<String, Integer> localidades;
    HashMap<String, Integer> unidades;
    HashMap<String, Integer> barrios;

    List<Zonificados> listaZonificados=new ArrayList<Zonificados>();
    List<Lider> listaLideres=new ArrayList<Lider>();
    /** Creates new form ConsultaExperta */
    public ConsultaExperta(java.awt.Frame parent) {
        super(parent, true);

        initComponents();
        pack();
        java.awt.Rectangle parentBounds = parent.getBounds();
        Dimension size = getSize();
        // Center in the parent
        int x = Math.max(0, parentBounds.x + (parentBounds.width - size.width) / 2);
        int y = Math.max(0, parentBounds.y + (parentBounds.height - size.height) / 2);
        setLocation(new Point(x, y));
        comboDepartamento.setSelectedIndex(1);
        zonaCombo.addItem("-- Seleccione una zona --");
        puestoCombo.addItem("-- Seleccione un Puesto --");
        comboMunicipios.addItem("-- Seleccione un municipio --");
        comboLocalidad.addItem("-- Seleccione una localidad --");
        comboUnidad.addItem("-- Seleccione una unidad comunera --");
        comboBarrio.addItem(" Seleccione un barrio --");
//        comboDepartamento.setEditable(false);
        listaraBarriosPorMunicipio();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBox1 = new javax.swing.JComboBox();
        jXTaskPaneContainer1 = new org.jdesktop.swingx.JXTaskPaneContainer();
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        comboDepartamento = new javax.swing.JComboBox();
        comboMunicipios = new javax.swing.JComboBox();
        detallesTabs = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        zonaCombo = new javax.swing.JComboBox();
        totalzoni = new org.jdesktop.swingx.JXTitledPanel();
        totalZonificados = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        puestoCombo = new javax.swing.JComboBox();
        consultarPorZona = new javax.swing.JButton();
        totalzoni3 = new org.jdesktop.swingx.JXTitledPanel();
        totalLideres = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        comboLocalidad = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        comboUnidad = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        comboBarrio = new javax.swing.JComboBox();
        totalzoni1 = new org.jdesktop.swingx.JXTitledPanel();
        totalZonificados1 = new javax.swing.JTextField();
        consultarPorLocalidad = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaZonificados = new javax.swing.JTable();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablaLideres = new javax.swing.JTable();
        jPanel5 = new javax.swing.JPanel();
        totalzoni2 = new org.jdesktop.swingx.JXTitledPanel();
        totalZonificados2 = new javax.swing.JTextField();
        comboBarrioPorBarrio = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        consultarPorBarrio = new javax.swing.JButton();
        campoLocalidad = new javax.swing.JTextField();
        uComuneraDeGov = new javax.swing.JTextField();

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Vani", 1, 18));
        jLabel1.setText("Consulta Experta");
        jXTaskPaneContainer1.add(jLabel1);

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED, java.awt.Color.gray, java.awt.Color.gray, java.awt.Color.lightGray, java.awt.Color.lightGray));

        jLabel2.setFont(new java.awt.Font("Lucida Bright", 0, 12));
        jLabel2.setText("Departamento");

        jLabel3.setFont(new java.awt.Font("Lucida Bright", 0, 12));
        jLabel3.setText("Municipio");

        listaraDepartamento();
        comboDepartamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboDepartamentoActionPerformed(evt);
            }
        });

        comboMunicipios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboMunicipiosActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(comboDepartamento, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(comboMunicipios, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(178, 178, 178))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(comboDepartamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(comboMunicipios, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        detallesTabs.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED, java.awt.Color.gray, java.awt.Color.gray, java.awt.Color.lightGray, java.awt.Color.lightGray), "Detalles de Consulta", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Lucida Bright", 1, 12))); // NOI18N
        detallesTabs.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                detallesTabsMouseClicked(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Lucida Bright", 0, 12));
        jLabel4.setText("Zonas:");

        zonaCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zonaComboActionPerformed(evt);
            }
        });

        totalzoni.setForeground(new java.awt.Color(255, 255, 255));
        totalzoni.setTitle(" Total zonificado");
        totalzoni.setTitleFont(new java.awt.Font("Tahoma", 3, 11));
        totalzoni.setTitleForeground(new java.awt.Color(255, 255, 255));
        totalzoni.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                totalzoniMouseClicked(evt);
            }
        });

        totalZonificados.setEditable(false);
        totalZonificados.setFont(new java.awt.Font("Tahoma", 1, 60));
        totalZonificados.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        totalZonificados.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                totalZonificadosMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout totalzoniLayout = new javax.swing.GroupLayout(totalzoni.getContentContainer());
        totalzoni.getContentContainer().setLayout(totalzoniLayout);
        totalzoniLayout.setHorizontalGroup(
            totalzoniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(totalzoniLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(totalZonificados, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)
                .addContainerGap())
        );
        totalzoniLayout.setVerticalGroup(
            totalzoniLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(totalzoniLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(totalZonificados, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
                .addContainerGap())
        );

        jLabel5.setFont(new java.awt.Font("Lucida Bright", 0, 12));
        jLabel5.setText("Puesto:");

        consultarPorZona.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zonasoft/Vistas/iconos/search-icon2.png"))); // NOI18N
        consultarPorZona.setText("Consultar");
        consultarPorZona.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                consultarPorZonaActionPerformed(evt);
            }
        });

        totalzoni3.setForeground(new java.awt.Color(255, 255, 255));
        totalzoni3.setTitle("Total Lideres");
        totalzoni3.setTitleFont(new java.awt.Font("Tahoma", 3, 11));
        totalzoni3.setTitleForeground(new java.awt.Color(255, 255, 255));
        totalzoni3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                totalzoni3MouseClicked(evt);
            }
        });

        totalLideres.setEditable(false);
        totalLideres.setFont(new java.awt.Font("Tahoma", 1, 60));
        totalLideres.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        totalLideres.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                totalLideresMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout totalzoni3Layout = new javax.swing.GroupLayout(totalzoni3.getContentContainer());
        totalzoni3.getContentContainer().setLayout(totalzoni3Layout);
        totalzoni3Layout.setHorizontalGroup(
            totalzoni3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(totalzoni3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(totalLideres, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE)
                .addContainerGap())
        );
        totalzoni3Layout.setVerticalGroup(
            totalzoni3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(totalzoni3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(totalLideres, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(12, 12, 12)
                        .addComponent(zonaCombo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(totalzoni3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(totalzoni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
                        .addComponent(consultarPorZona))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(puestoCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 234, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(110, 110, 110))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(puestoCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(zonaCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(55, 55, 55)
                        .addComponent(consultarPorZona))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(totalzoni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(totalzoni3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(23, Short.MAX_VALUE))
        );

        detallesTabs.addTab("Por  Zonas & Puestos", jPanel2);

        jLabel6.setFont(new java.awt.Font("Lucida Bright", 0, 12));
        jLabel6.setText("Localidad");

        comboLocalidad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboLocalidadActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Lucida Bright", 0, 12));
        jLabel7.setText("U. Comunera de GOV.");

        comboUnidad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboUnidadActionPerformed(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("Lucida Bright", 0, 12));
        jLabel8.setText("Barrio");

        totalzoni1.setForeground(new java.awt.Color(255, 255, 255));
        totalzoni1.setTitle(" Total zonificado");
        totalzoni1.setTitleFont(new java.awt.Font("Tahoma", 3, 11));
        totalzoni1.setTitleForeground(new java.awt.Color(255, 255, 255));

        totalZonificados1.setEditable(false);
        totalZonificados1.setFont(new java.awt.Font("Tahoma", 1, 60));
        totalZonificados1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        totalZonificados1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                totalZonificados1MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout totalzoni1Layout = new javax.swing.GroupLayout(totalzoni1.getContentContainer());
        totalzoni1.getContentContainer().setLayout(totalzoni1Layout);
        totalzoni1Layout.setHorizontalGroup(
            totalzoni1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(totalzoni1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(totalZonificados1, javax.swing.GroupLayout.DEFAULT_SIZE, 121, Short.MAX_VALUE)
                .addContainerGap())
        );
        totalzoni1Layout.setVerticalGroup(
            totalzoni1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(totalzoni1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(totalZonificados1, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
                .addContainerGap())
        );

        consultarPorLocalidad.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zonasoft/Vistas/iconos/search-icon2.png"))); // NOI18N
        consultarPorLocalidad.setText("Consultar");
        consultarPorLocalidad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                consultarPorLocalidadActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel8)
                            .addComponent(jLabel7))
                        .addGap(26, 26, 26)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(comboUnidad, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(comboLocalidad, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(comboBarrio, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(consultarPorLocalidad)
                        .addGap(84, 84, 84)))
                .addGap(29, 29, 29)
                .addComponent(totalzoni1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(73, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(totalzoni1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(comboLocalidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(comboUnidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(comboBarrio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))
                        .addGap(18, 18, 18)
                        .addComponent(consultarPorLocalidad)))
                .addContainerGap(38, Short.MAX_VALUE))
        );

        detallesTabs.addTab("Por localidades", jPanel3);

        tablaZonificados.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Id", "Nombre"," Apellido "," correo","telefono"
            }
        ));
        jScrollPane1.setViewportView(tablaZonificados);

        detallesTabs.addTab("Detalle Zonificados", jScrollPane1);

        tablaLideres.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Id", "Nombre"," Apellido "," correo","telefono"
            }));
            jScrollPane2.setViewportView(tablaLideres);

            javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
            jPanel4.setLayout(jPanel4Layout);
            jPanel4Layout.setHorizontalGroup(
                jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 576, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(49, Short.MAX_VALUE))
            );
            jPanel4Layout.setVerticalGroup(
                jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(28, Short.MAX_VALUE))
            );

            detallesTabs.addTab("Detalle Lideres", jPanel4);

            totalzoni2.setForeground(new java.awt.Color(255, 255, 255));
            totalzoni2.setTitle(" Total zonificado");
            totalzoni2.setTitleFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
            totalzoni2.setTitleForeground(new java.awt.Color(255, 255, 255));

            totalZonificados2.setEditable(false);
            totalZonificados2.setFont(new java.awt.Font("Tahoma", 1, 60));
            totalZonificados2.setHorizontalAlignment(javax.swing.JTextField.CENTER);
            totalZonificados2.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    totalZonificados2MouseClicked(evt);
                }
            });

            javax.swing.GroupLayout totalzoni2Layout = new javax.swing.GroupLayout(totalzoni2.getContentContainer());
            totalzoni2.getContentContainer().setLayout(totalzoni2Layout);
            totalzoni2Layout.setHorizontalGroup(
                totalzoni2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(totalzoni2Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(totalZonificados2, javax.swing.GroupLayout.DEFAULT_SIZE, 121, Short.MAX_VALUE)
                    .addContainerGap())
            );
            totalzoni2Layout.setVerticalGroup(
                totalzoni2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(totalzoni2Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(totalZonificados2, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
                    .addContainerGap())
            );

            comboBarrioPorBarrio.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    comboBarrioPorBarrioActionPerformed(evt);
                }
            });

            jLabel9.setFont(new java.awt.Font("Lucida Bright", 0, 12));
            jLabel9.setText("Barrio");

            jLabel10.setFont(new java.awt.Font("Lucida Bright", 0, 12));
            jLabel10.setText("Localidad");

            jLabel11.setFont(new java.awt.Font("Lucida Bright", 0, 12)); // NOI18N
            jLabel11.setText("U. Comunera de GOV.");

            consultarPorBarrio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zonasoft/Vistas/iconos/search-icon2.png"))); // NOI18N
            consultarPorBarrio.setText("Consultar");
            consultarPorBarrio.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    consultarPorBarrioActionPerformed(evt);
                }
            });

            javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
            jPanel5.setLayout(jPanel5Layout);
            jPanel5Layout.setHorizontalGroup(
                jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel5Layout.createSequentialGroup()
                            .addContainerGap(68, Short.MAX_VALUE)
                            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel9)
                                .addComponent(jLabel10))
                            .addGap(37, 37, 37))
                        .addGroup(jPanel5Layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jLabel11)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(comboBarrioPorBarrio, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(consultarPorBarrio)
                        .addComponent(uComuneraDeGov, javax.swing.GroupLayout.DEFAULT_SIZE, 243, Short.MAX_VALUE)
                        .addComponent(campoLocalidad))
                    .addGap(35, 35, 35)
                    .addComponent(totalzoni2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(60, 60, 60))
            );
            jPanel5Layout.setVerticalGroup(
                jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel5Layout.createSequentialGroup()
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPanel5Layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(totalzoni2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel5Layout.createSequentialGroup()
                            .addGap(37, 37, 37)
                            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel9)
                                .addComponent(comboBarrioPorBarrio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel10)
                                .addComponent(campoLocalidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel11)
                                .addComponent(uComuneraDeGov, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(18, 18, 18)
                            .addComponent(consultarPorBarrio)))
                    .addGap(32, 32, 32))
            );

            detallesTabs.addTab("Por Barrio", jPanel5);

            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jXTaskPaneContainer1, javax.swing.GroupLayout.DEFAULT_SIZE, 739, Short.MAX_VALUE)
                .addGroup(layout.createSequentialGroup()
                    .addGap(35, 35, 35)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(detallesTabs, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addContainerGap(52, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jXTaskPaneContainer1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(25, 25, 25)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(detallesTabs, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(20, Short.MAX_VALUE))
            );

            pack();
        }// </editor-fold>//GEN-END:initComponents

    private void comboDepartamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboDepartamentoActionPerformed
        String id = comboDepartamento.getSelectedItem().toString();
        int indice = comboDepartamento.getSelectedIndex();
       listaraBarriosPorMunicipio();        
        if (indice != 0) {
            Integer IdDepartamento = departamentos.get(id);
            listaraMunicipios(String.valueOf(IdDepartamento));
            comboMunicipios.setEnabled(true);
        } else {
            JOptionPane.showMessageDialog(null, "Seleccione un departamento primero");
        }

    }//GEN-LAST:event_comboDepartamentoActionPerformed

    private void comboMunicipiosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboMunicipiosActionPerformed
        // TODO add your handling code here:
        int tabActive = detallesTabs.getSelectedIndex();
        System.out.println("tabActive = " + tabActive);
        if (tabActive == 0) {
            listaraZonas();
        } else if (tabActive == 1) {
            listaraLocalidad();
        }
        if(tabActive == 4)
        {
          listaraBarriosPorMunicipio();
        }



    }//GEN-LAST:event_comboMunicipiosActionPerformed

    private void zonaComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zonaComboActionPerformed
        // TODO add your handling code here:
        listaraPuestos();
    }//GEN-LAST:event_zonaComboActionPerformed

    private void consultarPorZonaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_consultarPorZonaActionPerformed
        try {
            Map<String, Integer> filtros = new HashMap<String, Integer>();
            Map<String, String> resultados = new HashMap<String, String>();

            int indiceMunicipio = comboMunicipios.getSelectedIndex();
            int idMunicipio = 0;
            if (indiceMunicipio > 0) {
                String municipio = comboMunicipios.getSelectedItem().toString();
                idMunicipio = municipios.get(municipio);
            }
           
            int idZona = 0;
            int indiceZona = zonaCombo.getSelectedIndex();
            if (indiceZona > 0) {
                String zona = zonaCombo.getSelectedItem().toString();
                idZona = zonas.get(zona);
            }
           
            int idPuesto = 0;
            int indicePuesto = puestoCombo.getSelectedIndex();
            if (indicePuesto > 0) {
                String puesto = puestoCombo.getSelectedItem().toString();
                idPuesto = puestos.get(puesto);
            }

            int idDep=comboDepartamento.getSelectedItem().equals("Cero")?Integer.parseInt("0"):comboDepartamento.getSelectedIndex();


            filtros.put("idMunicipio", idMunicipio);
            filtros.put("idZona", idZona);
            filtros.put("idPuesto", idPuesto);
            filtros.put("idDep", idDep);

            ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
            ManejadorQuerys.con = (Connection) mbd.getConexion();

            if(((idMunicipio+idZona+idPuesto)>0) || comboDepartamento.getSelectedIndex()>0)
            {
                listaZonificados = ManejadorQuerys.consultaDinamica(filtros);
                listaLideres=ManejadorQuerys.consultaDinamicaLideres(filtros);
                listaZonificados(listaZonificados);
                listaLideres(listaLideres);
            }

            String totalZon = String.valueOf(listaZonificados.size());
            totalZonificados.setText(totalZon);
            String totalLid= String.valueOf(listaLideres.size());
            totalLideres.setText(totalLid);
        } catch (Exception ex) {
            Logger.getLogger(ConsultaExperta.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_consultarPorZonaActionPerformed

    private void comboLocalidadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboLocalidadActionPerformed
        // TODO add your handling code here:
        listaraUnidades();
    }//GEN-LAST:event_comboLocalidadActionPerformed

    private void comboUnidadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboUnidadActionPerformed
        // TODO add your handling code here:
        listaraBarrios();
    }//GEN-LAST:event_comboUnidadActionPerformed

    private void totalzoniMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_totalzoniMouseClicked
        // TODO add your handling code here:
         if (evt.getClickCount() == 1) {
         detallesTabs.setSelectedIndex(2);
         }
    }//GEN-LAST:event_totalzoniMouseClicked

    private void totalZonificadosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_totalZonificadosMouseClicked
        // TODO add your handling code here:
        if (evt.getClickCount() == 1) {
          if(listaZonificados.size()>0)
         detallesTabs.setSelectedIndex(2);
        }
    }//GEN-LAST:event_totalZonificadosMouseClicked

    private void totalZonificados1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_totalZonificados1MouseClicked
          if (evt.getClickCount() == 1) {
          if(listaZonificados.size()>0)
         detallesTabs.setSelectedIndex(2);
        }
    }//GEN-LAST:event_totalZonificados1MouseClicked

    private void consultarPorLocalidadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_consultarPorLocalidadActionPerformed
         try {
            Map<String, Integer> filtros = new HashMap<String, Integer>();
            Map<String, String> resultados = new HashMap<String, String>();


            int indiceMunicipio = comboMunicipios.getSelectedIndex();
            int idMunicipio = 0;
            if (indiceMunicipio > 0) {
                String municipio = comboMunicipios.getSelectedItem().toString();
                idMunicipio = municipios.get(municipio);
            }
            
            int idLocalidad = 0;
            int indiceLocalidad = comboLocalidad.getSelectedIndex();
            if (indiceLocalidad > 0) {
                String localidad= comboLocalidad.getSelectedItem().toString();
                idLocalidad = localidades.get(localidad);
            }
           
            int idBarrio = 0;
            int indiceBarrio = comboBarrio.getSelectedIndex();
            if (indiceBarrio > 0) {
                String barrio = comboBarrio.getSelectedItem().toString();
                idBarrio = barrios.get(barrio);
            }

            int idUnidad = 0;
            int indiceUidad = comboUnidad.getSelectedIndex();
            if (indiceUidad > 0) {
                String unidad = comboUnidad.getSelectedItem().toString();
                idUnidad = unidades.get(unidad);
            }

            filtros.put("idMunicipio", idMunicipio);
            filtros.put("idLocalidad", idLocalidad);
            filtros.put("idBarrio", idBarrio);
            filtros.put("idUnidad", idUnidad);
            
            ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
            ManejadorQuerys.con = (Connection) mbd.getConexion();
            if(((idMunicipio+idLocalidad+idBarrio+idUnidad)>0)|| comboDepartamento.getSelectedIndex()>0)
            {
             listaZonificados = ManejadorQuerys.consultaDinamicaPorLocalidad(filtros);
             listaZonificados(listaZonificados);
            }

            String total = String.valueOf(listaZonificados.size());
            totalZonificados1.setText(total);

        } catch (Exception ex) {
            Logger.getLogger(ConsultaExperta.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_consultarPorLocalidadActionPerformed

    private void detallesTabsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_detallesTabsMouseClicked
        // TODO add your handling code here:
//        if (evt.getClickCount() == 1 && (detallesTabs.getSelectedIndex()==1)) {
//          comboMunicipios.setSelectedIndex(0);
//        }
    }//GEN-LAST:event_detallesTabsMouseClicked

    private void totalLideresMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_totalLideresMouseClicked
        // TODO add your handling code here:
          if (evt.getClickCount() == 1) {
          if(listaZonificados.size()>0)
         detallesTabs.setSelectedIndex(3);
        }
    }//GEN-LAST:event_totalLideresMouseClicked

    private void totalzoni3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_totalzoni3MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_totalzoni3MouseClicked

    private void totalZonificados2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_totalZonificados2MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_totalZonificados2MouseClicked

    private void consultarPorBarrioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_consultarPorBarrioActionPerformed
        // TODO add your handling code here:
        try {
            Map<String, Integer> filtros = new HashMap<String, Integer>();
            Map<String, String> resultados = new HashMap<String, String>();

            listaraLocalidad();
            int indiceMunicipio = comboMunicipios.getSelectedIndex();
            int idMunicipio = 0;
            if (indiceMunicipio > 0) {
                String municipio = comboMunicipios.getSelectedItem().toString();
                idMunicipio = municipios.get(municipio);
            }
            
//            int idLocalidad = 0;
//            int indiceLocalidad = comboLocalidad.getSelectedIndex();
//            if (indiceLocalidad > 0) {
//                String localidad= comboLocalidad.getSelectedItem().toString();
//                idLocalidad = localidades.get(localidad);
//            }
            
            int idLocalidad = 0;
           if (!campoLocalidad.getText().isEmpty()  && campoLocalidad.getText()!=null) {
                String localidad= campoLocalidad.getText().toString();
                System.out.println("localidades = " + localidades.size());
                System.out.println("campoLocalidad.getText() = " + campoLocalidad.getText().trim());
                //idLocalidad = localidades.get(localidad);
            }
           
            int idBarrio = 0;
            int indiceBarrio = comboBarrioPorBarrio.getSelectedIndex();
            if (indiceBarrio > 0) {
                String barrio = comboBarrioPorBarrio.getSelectedItem().toString();
                System.out.println("barrio = " + barrio);
                
                //idBarrio = barrios.get(barrio);
            }

//            int idUnidad = 0;
//            int indiceUidad = comboUnidad.getSelectedIndex();
//            if (indiceUidad > 0) {
//                String unidad = comboUnidad.getSelectedItem().toString();
//                idUnidad = unidades.get(unidad);
//            }
            
            int idUnidad = 0;
           // int indiceUidad = comboUnidad.getSelectedIndex();
            if (!uComuneraDeGov.getText().isEmpty() && uComuneraDeGov.getText()!=null) {
                String unidad = uComuneraDeGov.getText();
                idUnidad = unidades.get(unidad);
            }

            filtros.put("idMunicipio", idMunicipio);
            filtros.put("idLocalidad", idLocalidad);
            filtros.put("idBarrio", idBarrio);
            filtros.put("idUnidad", idUnidad);
            
            ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
            ManejadorQuerys.con = (Connection) mbd.getConexion();
            if(((idMunicipio+idLocalidad+idBarrio+idUnidad)>0)|| comboDepartamento.getSelectedIndex()>0)
            {
             listaZonificados = ManejadorQuerys.consultaDinamicaPorLocalidad(filtros);
             listaZonificados(listaZonificados);
            }

            String total = String.valueOf(listaZonificados.size());
            totalZonificados2.setText(total);

        } catch (Exception ex) {
            Logger.getLogger(ConsultaExperta.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_consultarPorBarrioActionPerformed

    private void comboBarrioPorBarrioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboBarrioPorBarrioActionPerformed
        // TODO add your handling code here:
        listaraLocalidadPorBarrio();
    }//GEN-LAST:event_comboBarrioPorBarrioActionPerformed

     public void listaraLocalidadPorBarrio() {
        ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
        localidades = new HashMap<String, Integer>();
        String[] datos = new String[2];
        try {
            mbd.conectar();
            ManejadorLugar.con = (Connection) mbd.getConexion();
          if (comboBarrioPorBarrio.getItemCount() > 0) {
                String nombreBarrio = comboBarrioPorBarrio.getSelectedItem().toString();
                System.out.println("nombreBarrio = " + nombreBarrio);
                Integer idBa = barrios.get(nombreBarrio);
                System.out.println("idBa = " + idBa);
                datos = ManejadorLugar.getDatosLugar(String.valueOf(idBa));
//           Localidad loc = null;
//               while (iter.hasNext()){
//           loc = iter.next();
//           int codigo = Integer.parseInt(datos[2]);
//           comboLocalidad.addItem(datos[0]);  en el combo se le pone el nombre de este metodo
                campoLocalidad.setText(datos[0]);
                uComuneraDeGov.setText(datos[1]);
           }
//            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }// fin del listar localidades
    
    /**
     * @param args the command line arguments

    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    ConsultaExperta dialog = new ConsultaExperta(new javax.swing.JFrame(), true);
    dialog.addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent e) {
    System.exit(0);
    }
    });
    dialog.setVisible(true);
    }
    });
    } */
    public void listaraDepartamento() {
        ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
        departamentos = new HashMap<String, Integer>();
        try {
            mbd.conectar();
            ManejadorDepartamentos.con = (Connection) mbd.getConexion();
            comboDepartamento.removeAllItems();

            List listarDepartamento = null;
            listarDepartamento = ManejadorDepartamentos.listarDepartamentos();
            Iterator<Departamentos> iter = listarDepartamento.iterator();
            Departamentos dep = null;
            comboDepartamento.addItem("--Seleccione un departamento---");
            while (iter.hasNext()) {
                dep = iter.next();
                int codigoDepartamento = Integer.parseInt(dep.getCodigoDepartamento());
                comboDepartamento.addItem(dep.getNombre());
                departamentos.put(dep.getNombre(), codigoDepartamento);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    } // fin de listar departamentos

    public void listaraMunicipios(String idDepartamentos) {
        ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
        municipios = new HashMap<String, Integer>();
        try {
            mbd.conectar();
            ManejadorMunicipios.con = (Connection) mbd.getConexion();
            comboMunicipios.removeAllItems();
            List listarMunicipios = null;
            listarMunicipios = ManejadorMunicipios.listarMunicipios(idDepartamentos);
            Iterator<Municipios> iter = listarMunicipios.iterator();
            Municipios mun = null;
            comboMunicipios.addItem("-- Seleccione un municipio --");
            while (iter.hasNext()) {
                mun = iter.next();
                int codigoMunicipio = Integer.parseInt(mun.getCodigoMunicipio());
                comboMunicipios.addItem(mun.getNombre());
                municipios.put(mun.getNombre(), codigoMunicipio);
            }
            if(!comboDepartamento.getSelectedItem().equals("Cero"))
                 comboMunicipios.setSelectedIndex(9);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }// fin del listar Municipios

    public void listaraZonas() {
        ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
        zonas = new HashMap<String, Integer>();
        try {
            mbd.conectar();
            ManejadorZona.con = (Connection) mbd.getConexion();
            zonaCombo.removeAllItems();
            List listarZonas = null;
            if (comboMunicipios.getItemCount() > 1) {
                String idM = comboMunicipios.getSelectedItem().toString();
                Integer idMu = municipios.get(idM);
                listarZonas = ManejadorZona.listarZonas(String.valueOf(idMu));
                Iterator<Zona> iter = listarZonas.iterator();
                Zona zon = null;
                zonaCombo.addItem("-- Seleccione una zona --");
                while (iter.hasNext()) {
                    zon = iter.next();
                    int codigoZona = Integer.parseInt(zon.getCodigoZona());
                    zonaCombo.addItem(zon.getCodigoZona());
                    zonas.put(zon.getCodigoZona(), codigoZona);
                }
                if (zonaCombo.getItemCount() > 1) {
                    zonaCombo.setSelectedIndex(1);
                }
                listaraPuestos();
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void listaraPuestos() {
        ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
        puestos = new HashMap<String, Integer>();
        try {
            mbd.conectar();
            ManejadorPuesto.con = (Connection) mbd.getConexion();
            puestoCombo.removeAllItems();

            List listarPuestos = new ArrayList();

            int indice = zonaCombo.getSelectedIndex();
            puestoCombo.addItem("-- Seleccione un Puesto --");
            if (indice > 0) {
                String nombreZona = (zonaCombo.getSelectedItem().toString() != null) ? zonaCombo.getSelectedItem().toString() : "vacio";
                Integer idZona_ = zonas.get(nombreZona);

//            listarPuestos = ManejadorPuesto.listarPuestos();
                listarPuestos = ManejadorPuesto.listarPuestosByZona(String.valueOf(idZona_));

                Iterator<Puesto> iter = listarPuestos.iterator();
                Puesto Pue = null;

                while (iter.hasNext()) {
                    Pue = iter.next();
                    int idpuesto = Integer.parseInt(Pue.getIdPuesto());
                    puestoCombo.addItem(Pue.getNombrePuesto());
                    puestos.put(Pue.getNombrePuesto(), idpuesto);
                }
                AutoCompleteDecorator.decorate(puestoCombo);
                if (puestoCombo.getItemCount() > 1) {
                    puestoCombo.setSelectedIndex(1);
                }

            }
        } catch (Exception ex) {
            Logger.getLogger(RegistrarPuesto.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void listaraLocalidad() {
        ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
        localidades = new HashMap<String, Integer>();
        String[] datos = new String[2];
        try {
            mbd.conectar();
            ManejadorLugar.con = (Connection) mbd.getConexion();
            comboLocalidad.removeAllItems();
            List listarLocalidad = null;
            if (comboMunicipios.getItemCount() > 0) {
                String nombreMuni = comboMunicipios.getSelectedItem().toString();
                Integer idMuni = municipios.get(nombreMuni);

                listarLocalidad = ManejadorLugar.listarLocalidadByMunicipio(String.valueOf(idMuni));
                Iterator<Localidad> iter = listarLocalidad.iterator();
                Localidad loc = null;
                comboLocalidad.addItem("-- Seleccione una localidad --");
                while (iter.hasNext()) {
                    loc = iter.next();
                    int codigo = Integer.parseInt(loc.getCodigo());
                    comboLocalidad.addItem(loc.getNombre());
                    localidades.put(loc.getNombre(), codigo);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }// fin del listar localidades

    public void listaraUnidades() {
        ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
        unidades = new HashMap<String, Integer>();
        try {
            mbd.conectar();
            ManejadorLugar.con = (Connection) mbd.getConexion();
            comboUnidad.removeAllItems();
            List unidadesList = null;
            if (comboLocalidad.getItemCount() > 1) {
                String nombreLocali = comboLocalidad.getSelectedItem().toString();
                Integer idLocal = localidades.get(nombreLocali);

                unidadesList = ManejadorLugar.listarUnidadComuneraByLocalidad(String.valueOf(idLocal));
                Iterator<UnidadComunera> iter = unidadesList.iterator();
                UnidadComunera uni = null;
                comboUnidad.addItem("-- Seleccione una unidad comunera --");
                while (iter.hasNext()) {
                    uni = iter.next();
                    int codigo = Integer.parseInt(uni.getCodigo());
                    comboUnidad.addItem(uni.getNombre());
                    unidades.put(uni.getNombre(), codigo);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }// fin del listar Municipios

    public void listaraBarrios() {
        ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
        barrios = new HashMap<String, Integer>();
        try {
            mbd.conectar();
            ManejadorLugar.con = (Connection) mbd.getConexion();
            comboBarrio.removeAllItems();

            if (comboUnidad.getItemCount() > 1) {
                String nombreUnidad = comboUnidad.getSelectedItem().toString();
                Integer idUnidad = unidades.get(nombreUnidad);
                List listarBarrio = null;
                listarBarrio = ManejadorLugar.listarBarriosByUnidadComu(String.valueOf(idUnidad));
                Iterator<Barrio> iter = listarBarrio.iterator();
                Barrio bar = null;
                comboBarrio.addItem("-- Seleccione un Barrio --");
                while (iter.hasNext()) {
                    bar = iter.next();
                    int idBarrio = Integer.parseInt(bar.getIdBarrio());
                    comboBarrio.addItem(bar.getNombre());
                    barrios.put(bar.getNombre(), idBarrio);
                }
            }
        } catch (Exception ex) {
            Logger.getLogger(RegistrarPuesto.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
       public void listaraBarriosPorMunicipio() {
        ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
        barrios = new HashMap<String, Integer>();
        try {
            mbd.conectar();
            ManejadorLugar.con = (Connection) mbd.getConexion();
            comboBarrioPorBarrio.removeAllItems();

            List listarBarrio = null;
            listarBarrio = ManejadorLugar.listarBarrios();
            Iterator<Barrio> iter = listarBarrio.iterator();
            Barrio bar = null;
            comboBarrioPorBarrio.addItem("-- Seleccione un Barrio --");
            while (iter.hasNext()) {
                bar = iter.next();
                int idBarrio = Integer.parseInt(bar.getIdBarrio());
                comboBarrioPorBarrio.addItem(bar.getNombre());
                barrios.put(bar.getNombre(), idBarrio);
            }
        } catch (Exception ex) {
            Logger.getLogger(RegistrarPuesto.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

     public void listaZonificados(List<Zonificados> zon) {
        Date fechaHoy = new Date();
        int edadZonificado = 0;
        try {
            Iterator i = zon.iterator();
            DefaultTableModel dtm = (DefaultTableModel) tablaZonificados.getModel();
            Zonificados zo = new Zonificados();
            limpiarTablaZ();
            while (i.hasNext()) {
                zo = (Zonificados) i.next();
                // String fecha = String.valueOf(li.getFecha_registro());
//                    edadZonificado=fechaHoy.getYear()-zo.getFechadeNacimiento().getYear();
                Object[] fila = {zo.getIdZonificado(), zo.getNombres(), zo.getApellidos(), zo.getCorreo(), zo.getTelefono()};
                if (!zo.getIdLider().endsWith("_")) {
                    dtm.addRow(fila);
                }
                int r = dtm.getRowCount();
            }
        } catch (Exception ex) {
            Logger.getLogger(ConsultaExperta.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

     public void limpiarTablaZ() {
        DefaultTableModel dtm = (DefaultTableModel) tablaZonificados.getModel();
        dtm.setRowCount(0);
    }

     public void limpiarTablaL() {
        DefaultTableModel dtm = (DefaultTableModel) tablaLideres.getModel();
        dtm.setRowCount(0);
    }

      public void listaLideres(List<Lider> li) {
        Date fechaHoy = new Date();
        int edadZonificado = 0;
        try {
            Iterator i = li.iterator();
            DefaultTableModel dtm = (DefaultTableModel) tablaLideres.getModel();
            Lider lid = new Lider();
            limpiarTablaL();
            while (i.hasNext()) {
                lid = (Lider) i.next();
                // String fecha = String.valueOf(li.getFecha_registro());
//                    edadZonificado=fechaHoy.getYear()-zo.getFechadeNacimiento().getYear();
                Object[] fila = {lid.getIdLider(), lid.getNombre(), lid.getApellido(), lid.getCorreo(), lid.getTelefono()};
                if (!lid.getIdLider().endsWith("_")) {
                    dtm.addRow(fila);
                }
                int r = dtm.getRowCount();
            }
        } catch (Exception ex) {
            Logger.getLogger(ConsultaExperta.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField campoLocalidad;
    private javax.swing.JComboBox comboBarrio;
    private javax.swing.JComboBox comboBarrioPorBarrio;
    private javax.swing.JComboBox comboDepartamento;
    private javax.swing.JComboBox comboLocalidad;
    private javax.swing.JComboBox comboMunicipios;
    private javax.swing.JComboBox comboUnidad;
    private javax.swing.JButton consultarPorBarrio;
    private javax.swing.JButton consultarPorLocalidad;
    private javax.swing.JButton consultarPorZona;
    private javax.swing.JTabbedPane detallesTabs;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private org.jdesktop.swingx.JXTaskPaneContainer jXTaskPaneContainer1;
    private javax.swing.JComboBox puestoCombo;
    private javax.swing.JTable tablaLideres;
    private javax.swing.JTable tablaZonificados;
    private javax.swing.JTextField totalLideres;
    private javax.swing.JTextField totalZonificados;
    private javax.swing.JTextField totalZonificados1;
    private javax.swing.JTextField totalZonificados2;
    private org.jdesktop.swingx.JXTitledPanel totalzoni;
    private org.jdesktop.swingx.JXTitledPanel totalzoni1;
    private org.jdesktop.swingx.JXTitledPanel totalzoni2;
    private org.jdesktop.swingx.JXTitledPanel totalzoni3;
    private javax.swing.JTextField uComuneraDeGov;
    private javax.swing.JComboBox zonaCombo;
    // End of variables declaration//GEN-END:variables
}
